using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Utils;

public class CommonBox : MonoBehaviour
{
    public GameObject treasurePrefab;
    private Transform treasureTransform;
    private Transform coinTr, manaTr;

    public GameObject coinPrefab;
    public GameObject manaPrefab;

    private bool isOpen = false;

    private void Awake()
    {
        treasureTransform = UITool.GetChildGameObject("Treasure", gameObject).transform;
        coinTr = UITool.GetChildGameObject("Coin", gameObject).transform;
        manaTr = UITool.GetChildGameObject("Mana", gameObject).transform;
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (!isOpen && other.transform.tag.Equals("Player"))
        {
            if (treasurePrefab)
            {
                Instantiate(treasurePrefab, treasureTransform);
                // treasurePrefab.GetComponent<Weapon>().ResetForward();
            }

            if (coinPrefab) Instantiate(coinPrefab, coinTr);
            if (manaPrefab) Instantiate(manaPrefab, manaTr);

            GetComponent<Animator>().Play("BlueBlackBox_Open");

            isOpen = true;
        }
    }

    private void SetDropState()
    {
        manaPrefab.GetComponent<ManaCube>().canFly = true;
        coinPrefab.GetComponent<GoldCoin>().canFly = true;
    }
}